package org.csu.mypetstoreapi.service.impl;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.csu.mypetstoreapi.common.CommonResponse;
import org.csu.mypetstoreapi.entity.Order;
import org.csu.mypetstoreapi.entity.Product;
import org.csu.mypetstoreapi.entity.User;
import org.csu.mypetstoreapi.persistence.OrderMapper;
import org.csu.mypetstoreapi.service.OrderService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    private OrderMapper orderMapper;
    @Override
    public CommonResponse<Order> getOrder(int orderId) {
        Order order=orderMapper.selectById(orderId);
        if(order==null){
            return  CommonResponse.createForSuccessMessage("没有该ID的order");
        }
        return CommonResponse.createForSuccess(order);
    }

    @Override
    public CommonResponse<List<Order>> findAllOrders(User loginUser) {


        QueryWrapper<Order> orderQueryWrapper = new QueryWrapper<>();
        orderQueryWrapper.eq("userid",loginUser.getUsername());
        List<Order> orderList = orderMapper.selectList(orderQueryWrapper);
        if(orderList==null){
            return  CommonResponse.createForSuccessMessage("该用户没有order信息");
        }
        return CommonResponse.createForSuccess(orderList);
    }

    @Override
    public int getNextOrderId() {
        return 0;
    }

    @Override
    public void updateNextOrderId() {

    }
}
